Replace fdisk -l with sysfs-based disk enumeration (2tb+ drive support) #2035
Replace fdisk -l with sysfs-based disk enumeration (2tb+ drive support) #2035tlaurion wants to merge 3 commits intolinuxboot:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces fdisk -l commands with sysfs-based disk enumeration to overcome fdisk's 2TB drive size limitation and improve busybox compatibility. The changes enable proper detection and display of large storage devices (e.g., 8TB drives).
Key changes:
- Introduces
list_block_devices()function that reads from/sys/block/*instead of parsingfdisk -loutput - Replaces fdisk-based disk information gathering with sysfs-based size calculation
- Updates partition detection logic to use sysfs directory structure
Reviewed changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| initrd/etc/gui_functions | Adds list_block_devices() function and updates show_system_info() to read disk sizes from sysfs |
| initrd/etc/functions | Adds list_block_devices() function, updates device_has_partitions() to check sysfs for partitions, updates is_gpt_bios_grub() to read partition types from sysfs, and updates detect_boot_device() to use new function |
| initrd/bin/root-hashes-gui.sh | Updates detect_root_device() to use list_block_devices() instead of fdisk |
| initrd/bin/oem-system-info-xx30 | Updates disk information gathering to read from sysfs instead of fdisk |
| initrd/bin/config-gui.sh | Updates device listing to use list_block_devices() instead of fdisk |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b0bdb67 to
879fb3c
Compare
b3c8e82 to
d296082
Compare
12bbb04 to
23bcdbf
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
initrd/etc/functions:875
- disk_info_sysfs() builds disk_info lines using "\n" and then echoes with echo -n, which produces literal backslash-n sequences unless the consumer interprets escapes. To make output consistent across callers, prefer emitting real newlines via printf (e.g., printf 'Disk /dev/%s: %s GB\n' ...) or use printf '%b' when printing an escape-containing buffer.
local size_gb=$(((size_bytes * sector_size + 500000000) / 1000000000))
disk_info="${disk_info}Disk /dev/${devname}: ${size_gb} GB\n"
DEBUG "disk_info_sysfs: /dev/${devname} calculated as ${size_gb} GB (${size_bytes} sectors * ${sector_size} bytes/sector = $((size_bytes * sector_size)) bytes)"
fi
fi
done
echo -n "$disk_info"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2f37ee0 to
2971b52
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
initrd/etc/functions:832
list_block_devices()always exits 0 (even when it outputs nothing). Callers likeconfig-gui.shcurrently treat enumeration failure as an error (if ! list_block_devices ...; then ...), but that branch will never run now—an empty device list will instead reachfile_selector, which exits with a different error path. Consider havinglist_block_devicesreturn non-zero when no devices are found (or update callers to check for an empty output file explicitly).
# List all block devices using sysfs
# Outputs one device path per line (e.g., /dev/sda, /dev/vda, /dev/nvme0n1)
list_block_devices() {
TRACE_FUNC
for dev in /sys/block/sd* /sys/block/nvme* /sys/block/vd* /sys/block/hd*; do
if [ -e "$dev" ]; then
echo "/dev/$(basename "$dev")"
fi
done | sort
}
initrd/etc/functions:1347
- The comment says “otherwise check for grub type”, but the fdisk-based fallback was removed and the function now only checks
PARTTYPENAME=BIOS bootand then returns 1. Please update the comment (or reintroduce an actual fallback) so it matches the current behavior.
# Check partition type using sysfs if available, otherwise check for grub type
# For GPT disks, check /sys/class/block/<dev>/<partition>/uevent for PARTTYPENAME
local part_sys="/sys/class/block/$DEVICE/$(basename "$PART_DEV")"
if [ -e "$part_sys/uevent" ]; then
if grep -q "PARTTYPENAME=BIOS boot" "$part_sys/uevent"; then
TRACE "$PART_DEV is a GPT BIOS grub partition"
return 0
fi
fi
# Fallback: try to detect using other sysfs attributes if available
# For MBR disks, we would need to check partition type differently
DEBUG "$PART_DEV - unable to confirm it's a bios-grub partition via sysfs"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…bles
fdisk -l can’t be trusted inside Heads’ initrd: busybox limits it to
2 TiB and parsing its output is fragile.
Changes relative to origin/master:
* add new function disk_info_sysfs() in initrd/etc/functions
– walks /sys/block, skips partition entries, and computes a byte
count (preferring blockdev --getsize64, otherwise size*512)
– converts to decimal GB, switching to TB for ≥1000 GB
* update show_system_info() (gui_functions & oem‑system‑info‑xx30) to call the
helper and no longer invoke `fdisk -l` for size output
* add TRACE_FUNC/DEBUG logging around the helper invocation
Tested in qemu/debian‑13/PureOS; only the size line differs, other behaviour
is identical to master.
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
TODO: tpm prompt for password is silenced still.... Signed-off-by: Thierry Laurion <insurgo@riseup.net>
- harden shared initrd TPM/TOTP/HOTP, rollback-counter, reseal, and signing flows used across all boards - improve user-facing recovery guidance for reset vs reseal paths and add missing TPM2 primary-handle checks - stop swallowing interactive TPM counter prompts in sign/reset paths by fixing over-redirection - gate reseal/sign operations on GPG key availability and route to actionable GUI recovery choices - refine DUK passphrase prompt flow in kexec-seal-key for consistent inline entry behavior - add qemu tpm1/tpm2 prod_quiet board configs and correct *_hotp-prod_quiet board-name exports for coverage/testing
2971b52 to
3812659
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 16 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
initrd/etc/functions:1393
- The comment says
p<num>which looks like an HTML-escaped fragment and is confusing in a shell script comment. Replace it with a plain-text example likep<num>orp1.
# match nvme style (p<num>) or normal (digit suffix)
initrd/etc/functions:958
- Avoid logging any information about secrets, including password length. Even in debug logs this can leak sensitive metadata and is unnecessary for normal troubleshooting. Drop this log line or replace it with a generic message that doesn’t include derived properties of the password.
read -r -s -p $'\nTPM Owner Password: ' tpm_owner_password
echo
# Cache the password externally to be reused by who needs it
DEBUG "password length ${#tpm_owner_password}"
initrd/etc/functions:1484
mounted_boot_devis assigned withoutlocal, which can leak/overwrite a global variable in this large sharedfunctionsfile and make later logic harder to reason about. Declare it aslocal mounted_boot_dev(and considerlocal CONFIG_BOOT_DEVbehavior) to keepdetect_boot_deviceside effects intentional.
mounted_boot_dev="$(awk '$2=="/boot" {print $1; exit}' /proc/mounts)"
if [ -n "$mounted_boot_dev" ] && ls -d /boot/grub* >/dev/null 2>&1; then
CONFIG_BOOT_DEV="$mounted_boot_dev"
return 0
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # match nvme style (p<num>) or normal (digit suffix) | ||
| if [[ $partname =~ ^(.+?)(p?[0-9]+)$ ]]; then | ||
| device="${BASH_REMATCH[1]}" | ||
| number="${BASH_REMATCH[2]}" | ||
| number="${number#p}" |
There was a problem hiding this comment.
This bash regex uses .+? (PCRE-style non-greedy) which is not valid in bash ERE and can trigger [[ ... =~ ... ]] regex compilation errors at runtime. Update the parsing logic to use bash-compatible patterns (often easiest as two explicit matches: one for ...p<digits> devices like nvme/mmcblk, and one for plain digit-suffixed partitions like sdX1).
| # match nvme style (p<num>) or normal (digit suffix) | |
| if [[ $partname =~ ^(.+?)(p?[0-9]+)$ ]]; then | |
| device="${BASH_REMATCH[1]}" | |
| number="${BASH_REMATCH[2]}" | |
| number="${number#p}" | |
| # match nvme/mmcblk style (ending with p<num>) first, then normal (digit suffix) | |
| if [[ $partname =~ ^(.+p)([0-9]+)$ ]]; then | |
| # e.g. nvme0n1p2 -> device=nvme0n1, number=2 | |
| device="${BASH_REMATCH[1]%p}" | |
| number="${BASH_REMATCH[2]}" | |
| elif [[ $partname =~ ^(.+)([0-9]+)$ ]]; then | |
| # e.g. sda1 -> device=sda, number=1 | |
| device="${BASH_REMATCH[1]}" | |
| number="${BASH_REMATCH[2]}" |
fdisk -l can deal with 2TB max size drives. Use linux sysfs instead.
Tested:
Fixes #2034 (should have been the fix for #1884)